# Contributor: ScrumpyJack <scrumpyjack@st.ilet.to>
# Maintainer: Celeste <cielesti@protonmail.com>
pkgname=dillo
pkgver=3.1.0_git20240506
_gitrev=fc6a26c98fc7aa03db11cab1e3be2a52051650e4
pkgrel=0
pkgdesc="Fast and small graphical web browser"
url="https://github.com/dillo-browser/dillo"
arch="all"
license="GPL-3.0-or-later"
depends="ca-certificates wget"
makedepends="
	autoconf
	automake
	fltk-dev
	libjpeg-turbo-dev
	libpng-dev
	libx11-dev
	openssl-dev
	zlib-dev
	"
checkdepends="expect xvfb-run"
subpackages="$pkgname-doc"
source="https://github.com/dillo-browser/dillo/archive/$_gitrev/dillo-browser-$_gitrev.tar.gz"
builddir="$srcdir/$pkgname-$_gitrev"
options="net" # tests check HTTPS connectivity

prepare() {
	default_prepare

	./autogen.sh
}

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--enable-png \
		--enable-gif \
		--enable-jpeg \
		--enable-ipv6 \
		--enable-tls \
		--with-ca-certs-dir=/etc/ssl/certs

	make
}

check() {
	export DILLO_TESTBIN="${DILLO_TESTBIN:-"./src/dillo"}"
	export DILLO_TESTSITE="${DILLO_TESTSITE:-"alpinelinux.org"}"

	msg "Running tests for $($DILLO_TESTBIN --version)"

	msg "Running Dillo HTTPS check"
	HOME="$srcdir" xvfb-run -a expect -f - <<-'END'
		set testsite $env(DILLO_TESTSITE)
		spawn $env(DILLO_TESTBIN) https://${testsite}
		set domain [lindex [split $testsite /] 0]
		expect {
			timeout { exit 1 }
			-re [concat $domain: {TLSv1.\d, cipher}] {
				exit 0
			}
		}
	END

	msg "Running the Dillo test suite"
	make check || {
		cat test/html/test-suite.log
		return 1
	}
}

package() {
	make DESTDIR="$pkgdir" install

	install -Dm644 AUTHORS ChangeLog README NEWS \
		-t "$pkgdir"/usr/share/doc/$pkgname/
}

doc() {
	default_doc

	install -dv "$pkgdir"/usr/share/doc/$pkgname
	mv -vt "$pkgdir"/usr/share/doc/$pkgname/ \
		"$subpkgdir"/usr/share/doc/$pkgname/user_help.html
}

sha512sums="
31c468390383775b396c7dbb49db9fe430912e272de3bb1816065497b38a01913e3635ef02ed45450441241e270b01d4b061e7f7add73a8202c07f6bb85404cd  dillo-browser-fc6a26c98fc7aa03db11cab1e3be2a52051650e4.tar.gz
"
